#coding=utf-8
from sklearn.linear_model import LinearRegression
import numpy as np
import matplotlib.pyplot as plt

x= np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]).reshape(-1, 1)
y= np.array([3.1, 5.0, 7.2, 9.1, 11.0, 13.1, 15.0, 16.8, 19.2, 21.0])

model= LinearRegression()
model.fit(x, y)

b=model.coef_[0]  # 线性回归的斜率
a=model.intercept_ # 线性回归的截距
print("斜率:", b)
print("截距:", a)
print(f"拟合结果: y = {b:.2f} * x + {a:.2f}")
print("预测结果:", model.predict([[32.0]]))